package com.yanqu.road.server.manager.monopolymarket;

import com.yanqu.road.entity.monopolymarket.office.log.MonopolyMarketFortressSettlementLogData;
import com.yanqu.road.entity.monopolymarket.office.log.MonopolyMarketOfficeRobLogData;
import com.yanqu.road.entity.monopolymarket.office.log.MonopolyMarketResGrabRobLogData;
import com.yanqu.road.logic.bussiness.log.LogBussiness;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Author cwq
 * @Data 2021/10/9 20:19
 */
public class MonopolyMarketLogMgr {

    private static List<MonopolyMarketOfficeRobLogData> logMonopolyMarketOfficeRobLogDataList = new ArrayList<>();
    private static List<MonopolyMarketResGrabRobLogData> logMonopolyMarketResGrabRobLogDataList = new ArrayList<>();
    private static List<MonopolyMarketFortressSettlementLogData> logMonopolyMarketFortressSettlementLogDataList = new ArrayList<>();


    public static void addMonopolyMarketOfficeRobLogData(MonopolyMarketOfficeRobLogData item){
        synchronized (logMonopolyMarketOfficeRobLogDataList){
            logMonopolyMarketOfficeRobLogDataList.add(item);
        }
    }

    public static void addMonopolyMarketResGrabRobLogData(MonopolyMarketResGrabRobLogData item){
        synchronized (logMonopolyMarketResGrabRobLogDataList){
            logMonopolyMarketResGrabRobLogDataList.add(item);
        }
    }

    public static void addMonopolyMarketFortressSettlementLogData(MonopolyMarketFortressSettlementLogData item){
        synchronized (logMonopolyMarketFortressSettlementLogDataList){
            logMonopolyMarketFortressSettlementLogDataList.add(item);
        }
    }

    public static void saveLog() {
        if (!CollectionUtils.isEmpty(logMonopolyMarketOfficeRobLogDataList)) {
            List<MonopolyMarketOfficeRobLogData> list;
            synchronized (logMonopolyMarketOfficeRobLogDataList) {
                list = new ArrayList<>(logMonopolyMarketOfficeRobLogDataList);
                logMonopolyMarketOfficeRobLogDataList.clear();
            }
            LogBussiness.addLogMonopolyMarketOfficeRobLogData(list);
        }
        if (!CollectionUtils.isEmpty(logMonopolyMarketResGrabRobLogDataList)) {
            List<MonopolyMarketResGrabRobLogData> list;
            synchronized (logMonopolyMarketResGrabRobLogDataList) {
                list = new ArrayList<>(logMonopolyMarketResGrabRobLogDataList);
                logMonopolyMarketResGrabRobLogDataList.clear();
            }
            LogBussiness.addLogMonopolyMarketResGrabRobLogData(list);
        }
        if (!CollectionUtils.isEmpty(logMonopolyMarketFortressSettlementLogDataList)) {
            List<MonopolyMarketFortressSettlementLogData> list;
            synchronized (logMonopolyMarketFortressSettlementLogDataList) {
                list = new ArrayList<>(logMonopolyMarketFortressSettlementLogDataList);
                logMonopolyMarketFortressSettlementLogDataList.clear();
            }
            LogBussiness.addLogMonopolyMarketFortressSettlementLogData(list);
        }
    }
}
